﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tour.szhome.common;
using TOUR.SZHOME.BLL;
using TOUR.SZHOME.Entity;

namespace tour.szhome.www.Controllers
{
    public class XiangMuController : Controller
    {
        //
        // GET: /Project/
        ProjectsBLL _pbll = new ProjectsBLL();
        Projects_UnitBLL _unitbll = new Projects_UnitBLL();
        Projects_NewBLL _newsbll = new Projects_NewBLL();
        Projects_ImageBLL _pimgbll = new Projects_ImageBLL();

        /// <summary>
        /// 获取项目列表 --  前台
        /// </summary>
        /// <param name="XMLB"></param>
        /// <param name="WYLX"></param>
        /// <returns></returns>
        public ActionResult Index(int XMLB = 8,int WYLX = 8)
        {
            string strXMLB = StringHelper.ConvertLBToStr(XMLB);
            string strWYLX = StringHelper.ConvertLXToStr(WYLX);
            ViewBag.Total = _pbll.GetCount(strXMLB, strWYLX);
            ViewBag.List = _pbll.GetToWeb(strXMLB, strWYLX);
            return View();
        }

        /// <summary>
        /// 项目详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Detail(int id = 0) 
        {
            ViewBag.ID = id;
            ViewBag.PName = _pbll.GetProjectNameByID(id);

            ProjectsEntity model = new ProjectsEntity();
            model = _pbll.GetProjectByID(id);

            ViewBag.HModel = _unitbll.GetUnitByID(id);

            PageSet pageSet = new PageSet(){PageIndex = 1,PageSize = 8,};
            ViewBag.NList = _newsbll.GetNewsListByPID(id, pageSet);

            var list = _pimgbll.GetListByXMID(id);
            ViewBag.sList = list.Where(x => x.TPLX == 0).ToList(); //实景图
            ViewBag.xList = list.Where(x => x.TPLX == 1).ToList(); //效果图
            ViewBag.gList = list.Where(x => x.TPLX == 2).ToList(); //规划图
            ViewBag.pList = list.Where(x => x.TPLX == 3).ToList(); //配套图
            ViewBag.hList = list.Where(x => x.TPLX == 4).ToList(); //活动图

            //户型统计
            ViewBag.XMLXL = _unitbll.GetHXListByAttr(id,1);
            ViewBag.XMHXL = _unitbll.GetHXListByAttr(id,0);
            return View(model);
        }

        /// <summary>
        /// 项目 -- 户型
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Unit(int id = 0)
        {
            ViewBag.ID = id;
            ProjectsEntity model = new ProjectsEntity();
            model = _pbll.GetProjectByID(id);
            ViewBag.PName = _pbll.GetProjectNameByID(id);
            ViewBag.HModel = _unitbll.GetZTHXModel(id);
            return View(model);
        }

        /// <summary>
        /// 项目--交通配套
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult JiaoTong(int id = 0)
        {
            ViewBag.ID = id;
            ViewBag.PName = _pbll.GetProjectNameByID(id);
            ProjectsEntity model = new ProjectsEntity();
            model = _pbll.GetProjectByID(id);
            return View(model);
        }

        /// <summary>
        /// 项目动态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult News(int id = 0)
        {
            ViewBag.ID = id;
            ViewBag.PName = _pbll.GetProjectNameByID(id);// 获取项目名称
            //新闻列表
            PageSet pageSet = new PageSet() { PageIndex = 1, PageSize = 8, };
            ViewBag.NList = _newsbll.GetNewsListByPID(id, pageSet);
            //项目实体
            ProjectsEntity model = new ProjectsEntity();
            model = _pbll.GetProjectByID(id);
            return View(model);
        }

        //详情--详情
        public ActionResult DetailX(int id = 0)
        {
            ViewBag.ID = id;
            ViewBag.PName = _pbll.GetProjectNameByID(id);
            ProjectsEntity model = new ProjectsEntity();
            model = _pbll.GetProjectByID(id);
            return View(model);
        }

        /// <summary>
        /// 根据条件获取 户型统计列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [ActionName("get_hx_list_by_type")]
        public ActionResult GetHXListByAttr(int pid = 0, int type = 1) 
        {
            var listdata = _unitbll.GetHXListByAttr(pid, type);
            var data = new { 
                list = listdata,
                count = listdata.Count
            };
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 获取项目 -- 户型 -- 某种Type -- 展开详情（带图） -- 暂不分页
        /// </summary>
        /// <param name="pid">项目ID</param>
        /// <param name="attr">属性： 跟据Type不同入参也不同</param>
        /// <param name="type"></param>
        /// <returns></returns>
        [ActionName("get_hx_detail_by_type")]
        public ActionResult GetHXListByAttr(int pid = 0, string attr = "", int type = 1)
        {
            return Json(_unitbll.GetHXDetailByAttr(pid, attr,type), JsonRequestBehavior.AllowGet);
        }
    }
}
